import { useTitle } from '@vueuse/core';
import { unref, watch } from 'vue';
import type { MaybeRef } from '@vueuse/core';

/**
 * 设置应用标题
 *
 * @param title 标题
 */
export function useAppTitle(title: MaybeRef<string>) {
  const globalTitle = import.meta.env.VITE_APP_TITLE;
  
  const setTitle = useTitle();
  
  watch(
    () => unref(title),
    val => {
      setTitle.value = val ? `${val} - ${globalTitle}` : globalTitle;
    },
    { immediate: true }
  );
} 